/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014年12月27日         Root.Lu
 */

package com.coocaa.launcher.framework.launcherhost.statusbar;

import android.content.Context;

import com.coocaa.launcher.framework.launcherhost.LauncherHostViewController;
import com.coocaa.launcher.framework.launcherhost.statusbar.StatusBarPlugin.IStatusBarPluginListener;

public final class StatusBarHostViewController implements IStatusBarPluginListener {
    private static StatusBarHostViewController instance = null;

    public static void init(Context context) {
        // TODO Auto-generated method stub
        if (instance == null) {
            instance = new StatusBarHostViewController(context);
            StatusBarPlugin.setContext(context);
        }
    }

    public static void uninit() {
        // TODO Auto-generated method stub
        instance = null;
    }

    public static StatusBarHostViewController getInstance() {
        return instance;
    }

    private StatusBarHostView view = null;

    private StatusBarHostViewController(Context context) {

    }

    public void setStatusBarHostView(StatusBarHostView view) {
        this.view = view;
    }

    public StatusBarHostView getStatusBarHostView() {
        return view;
    }

    public void add(StatusBarPlugin item) {
        item.setListener(this);
        item.create();
    }

    public void remove(StatusBarPlugin item) {
        item.destroy();
    }

    @Override
    public void onStatusBarPluginCreate(StatusBarPlugin item) {
        // TODO Auto-generated method stub
        if (view != null)
            view.add(item.inflate(LauncherHostViewController.hostContext.getCurrentPattern()));
    }

    @Override
    public void onStatusBarPluginDestroy(StatusBarPlugin item) {
        // TODO Auto-generated method stub
        if (view != null)
            view.remove(item.inflate(LauncherHostViewController.hostContext.getCurrentPattern()));
        item.setListener(null);
    }
}
